#include <stdio.h>
#include <stdlib.h>




typedef struct Node
{

	int item;
	struct Node *pNext;
	struct Node *pPre;

}NodeItem;



NodeItem *InitLinkTable(size_t len)
{


	int i;

	NodeItem *pPre=NULL,*pNow=NULL,*pHead=(NodeItem *)malloc(sizeof(NodeItem)*len);


	if(pHead==NULL)
	{
	
		return NULL;
	}

	pHead->item=1;
	pNow=pPre=pHead;

	pPre->pNext=pNow;
	pNow->pPre=pPre;
	for(i=0;i<len;i++)
	{
	
		 pNow=(pHead+i);
		 pNow->item=i+1;
		 pNow->pNext=pHead;
		 pHead->pPre=pNow;

		 pPre->pNext=pNow;
		 pNow->pPre=pPre;
		 
		 pPre=pNow;
	
	}


	return pHead;
}



static void deleteNode(NodeItem *pNode)
{

	if(pNode==NULL)
	{
		return;
	}
	

	
	pNode->pNext->pPre=pNode->pPre;
	pNode->pPre->pNext=pNode->pNext;

}



#define NUM 3

int main()
{

	int i;
	NodeItem *pPre=NULL,*pNow=NULL,*pHead=InitLinkTable(8);


	pNow=pHead;
	
	do{	
		printf("%d\n",pNow->item);
		pNow=pNow->pNext;
	}while(pNow!=pHead);



	pNow=pHead;
	
	while(pNow->pNext!=pNow)
	{
		
		for(i=0;i<NUM;i++)
		{
		
			pNow=pNow->pNext;
		}
		

		printf("print the number out %d\n",pNow->item);
		deleteNode(pNow);
	
	}


	
	return 0;

}
